<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="getList"
    @getDetail="getDetail"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">档案编号</view>
          <view class="rl">{{ item.fileNo }}</view>
        </view>
        <view class="option">
          <view class="lf">项目名称</view>
          <view class="rl">{{ item.projectId_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">项目编号</view>
          <view class="rl">{{ item.projectNo }}</view>
        </view>
        <view class="option">
          <view class="lf">签订单位</view>
          <view class="rl">{{ item.signUnit_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">档案所属团队</view>
          <view class="rl">{{ item.archiveBelongingTeam_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">业务名称</view>
          <view class="rl">{{ item.businessName_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">项目负责人</view>
          <view class="rl">{{ item.projectLeader_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">密级</view>
          <view class="rl">{{ item.secrecyLevel_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">存档人</view>
          <view class="rl">{{ item.archivePerson_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">存档位置</view>
          <view class="rl">{{ item.archiveLocation }}</view>
        </view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { erpProjectArchiveFileList, erpProjectArchiveFileById } from '@/api/index.js'

export default {
  name: 'HSelectProjectArchiveInputPopup',
  data() {
    return {
      getList: erpProjectArchiveFileList,
      params: {
        column: 'createTime',
        order: 'desc',
        pageNo: 1,
        pageSize: 10,
        archiveMajorCategory: '',
        archiveMinorCategory: '',
        field: 'id,,,fileNo,projectId_dictText,projectNo,signUnit_dictText,archiveBelongingTeam_dictText,businessName_dictText,projectLeader_dictText,secrecyLevel_dictText,archivePerson_dictText,archiveLocation',
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    muitFlag: {
      type: Boolean,
      default: false,
    },
    archiveMajorCategory: {
      type: String,
      default: ''
    },
    archiveMinorCategory: {
      type: String,
      default: ''
    }
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      },
    },
    queryParams() {
      const params = {
        ...this.params,
      }
      if (this.keywords) {
        params.fileNo = '*' + this.keywords + '*'
      }
      return params
    },
  },
  watch: {
    archiveMajorCategory: {
      handler(big) {
        this.$set(this.params, 'archiveMajorCategory', big)
      },
      deep: true,
    },
    archiveMinorCategory: {
      handler(small) {
        this.$set(this.params, 'archiveMinorCategory', small)
      },
      deep: true,
    },
  },
  methods: {
    // 获取详情
    getDetail(value) {
      erpProjectArchiveFileById({ id: value }).then((res) => {
        if (res.success) {
          this.$refs.hSelectInputPopup.title = res.result.billNo
          this.$emit('select', {
            data: res.result,
            id: value,
          })
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>

// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
